from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep


#调用驱动，打开Chrome浏览器
driver = webdriver.Chrome()
sleep(2)
#输入网址，打开百度新闻网站
driver.get('https://news.baidu.com')
sleep(2)
#单击热点新闻第一条
firstnews = driver.find_element(By.XPATH, "//*[@id='pane-news']/div/ul/li[1]/strong/a").click()
sleep(2)
current = driver.current_window_handle
all_handles = driver.window_handles
print(current)
driver.switch_to.window(all_handles[1])
print(driver.current_window_handle)
print(driver.title)

